//package com.expression.common.utils;
//
//import cn.hutool.core.util.StrUtil;
//import com.expression.common.exception.AppException;
//import io.jsonwebtoken.Claims;
//import io.jsonwebtoken.Jws;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//
//@Component
//public class TokenUtils {
//    @Autowired
//    private JwtUtils jwtUtils;
//
//    public Long getUserIdFromReq(HttpServletRequest req) {
//        String authToken = req.getHeader(AppConstant.TOKEN);
//        if (StrUtil.isBlank(authToken)) {
//            throw new AppException("token不存在");
//        }
//        //  解析jwt字符串
//        Jws<Claims> claimsJws = jwtUtils.parseToken(authToken);
//        //token字符串解析失败
//        if (claimsJws == null || StrUtil.isBlank(claimsJws.getBody().getSubject())) {
//            throw new AppException("token解析错误");
//        }
//        return  Long.parseLong(claimsJws.getBody().getSubject());
//    }
//}
